package com.stx.luyudong;

import java.io.FileInputStream;
import java.io.ObjectInputStream;
public class DeserializeDemo {
    public static void main(String[] args) {
        //反序列化-Users
        try {
            //打开序列化文件
            FileInputStream fileInputStream = new FileInputStream("E:/class/test.txt");
            //反序列化
            ObjectInputStream objectInputStream;
            objectInputStream = new ObjectInputStream(fileInputStream);
            //读取文件
            Users reader0 = (Users) objectInputStream.readObject();
            Users reader1 = (Users) objectInputStream.readObject();
            //用户提示
            System.out.println("厉害！对象读出来了！");
            //输出反序列化后的结果
            System.out.println("读出来的信息是："+ reader0.toString());
            System.out.println("读出来的信息是："+ reader1.toString());
            //捕获在 try 块中可能发生的任何异常
        }catch (Exception e){
            //打印异常信息
            System.out.println("哎呀，读的时候出错了！");
            e.printStackTrace();
        }
    }
}